package com.example.safeassistan.utile;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class WeekUtils {
    public static String getWeek(String pTime) {
        String week = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        try {
            c.setTime(format.parse(pTime));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            week += "星期天";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 2) {
            week += "星期一";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 3) {
            week += "星期二";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 4) {
            week += "星期三";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 5) {
            week += "星期四";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 6) {
            week += "星期五";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 7) {
            week += "星期六";
        }
        return week;
    }

    public static Calendar getdate(String time,int count) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar ca = Calendar.getInstance();
        try {
            ca.setTime(format.parse(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        ca.add(Calendar.DAY_OF_MONTH, count);
        return ca;
    }
}
